package src.dual_pointers;

/**
 * @author starsea
 * @date 2024-08-25 22:41
 */

public class Test10 {
    public static void main(String[] args) {
        int[] arr={3,2,1};
        int c=jump(arr);

    }
    public static int jump(int[] nums) {
       int left=0;
       int right=0;
       int ret=0;
       int maxPos=0;
       int n=nums.length;
       while(left<=right)
       {
           if(maxPos>=n-1)
           {
               return ret;
           }
           for(int i=left ;i<=right;i++)
           {
               maxPos=Math.max(maxPos,nums[i]+i);
           }
           left=right+1;
           right=maxPos;
           ret++;
       }
       return -1;
    }
}
